package com.wei.czz.common.property;

import com.wei.czz.common.enums.admin.user.RequestChannelEnum;
import com.wei.czz.common.tool.BaseEntity;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;
import org.springframework.validation.annotation.Validated;

import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * Created by IntelliJ IDEA.
 *
 * @author wyw
 * date: 2024-06-10 11:20:12
 * className: JwtProperty
 * version: 1.0
 * description:
 */
@Getter
@Setter
@Component
@ConfigurationProperties(prefix = "jwt")
@Validated
public class JwtProperty extends BaseEntity {

    /**
     * 令牌主题
     */
    @NotBlank(message = "令牌主题不能为空")
    private String subject;

    /**
     * 令牌发布者
     */
    @NotBlank(message = "令牌发布者不能为空")
    private String issuer;

    /**
     * 令牌密钥
     */
    @NotBlank(message = "令牌密钥不能为空")
    private String secret;

    /**
     * web端令牌过期时间
     * 单位：秒
     */
    @NotNull(message = "web端令牌过期时间不能为空")
    private Long webExpire;

    /**
     * 令牌过期时间
     * 根据登录渠道，获取对应令牌过期时间
     * @param requestChannelEnum 登录渠道枚举对象
     * @return 令牌过期时间
     */
    public Long getExpire(RequestChannelEnum requestChannelEnum) {
        switch (requestChannelEnum) {
            case WEB:
                return webExpire * 1000;
            default:
                return 0L;
        }
    }
}
